package com.school.campus.service.impl;

import java.util.List;

import com.school.campus.domain.StudyRoom;
import com.school.campus.mapper.StudyRoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.school.campus.mapper.SeatMapper;
import com.school.campus.domain.Seat;
import com.school.campus.service.ISeatService;

/**
 * 座位信息Service业务层处理
 *
 * @author wwj
 * @date 2025-10-31
 */
@Service
public class SeatServiceImpl implements ISeatService {
    @Autowired
    private SeatMapper seatMapper;
    @Autowired
    private StudyRoomMapper studyRoomMapper;

    /**
     * 查询座位信息
     *
     * @param id 座位信息主键
     * @return 座位信息
     */
    @Override
    public Seat selectSeatById(Long id) {
        return seatMapper.selectSeatById(id);
    }

    /**
     * 查询座位信息列表
     *
     * @param seat 座位信息
     * @return 座位信息
     */
    @Override
    public List<Seat> selectSeatList(Seat seat) {
        return seatMapper.selectSeatList(seat);
    }

    /**
     * 新增座位信息
     *
     * @param seat 座位信息
     * @return 结果
     */
    @Override
    public int insertSeat(Seat seat) {
        return seatMapper.insertSeat(seat);
    }

    /**
     * 修改座位信息
     *
     * @param seat 座位信息
     * @return 结果
     */
    @Override
    public int updateSeat(Seat seat) {
        return seatMapper.updateSeat(seat);
    }

    /**
     * 批量删除座位信息
     *
     * @param ids 需要删除的座位信息主键
     * @return 结果
     */
    @Override
    public int deleteSeatByIds(Long[] ids) {
        return seatMapper.deleteSeatByIds(ids);
    }

    /**
     * 删除座位信息信息
     *
     * @param id 座位信息主键
     * @return 结果
     */
    @Override
    public int deleteSeatById(Long id) {
        return seatMapper.deleteSeatById(id);
    }

    @Override
    public int reserveSeat(Long seatId) {
        Seat seat = seatMapper.selectSeatById(seatId);
        seat.setStatus(1L); // 表示已有人
        int i = seatMapper.updateSeat(seat);
        StudyRoom studyRoom = studyRoomMapper.selectStudyRoomById(seat.getStudyRoomId());
        studyRoom.setReservedPeople(studyRoom.getReservedPeople() + 1);
        studyRoomMapper.updateStudyRoom(studyRoom);
        return i;
    }


}
